﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_CommonLayout.cshtml";
}
<script type="text/javascript" src="~/Scripts/jquery-easyui/jquery.easyui.min.js"></script>
<link type="text/css" href="~/Scripts/jquery-easyui/themes/default/easyui.css" rel="stylesheet" />
<link type="text/css" href="~/Scripts/jquery-easyui/themes/icon.css" rel="stylesheet" />
<link type="text/css" href="~/Content/themes/project/loading.css" rel="stylesheet"/>
<div id="reportdiv"  style="height:560px;width:1100px;">
    <input id="startTime" value="@ViewBag.startTime" type="hidden" />
    <input id="endTime" value="@ViewBag.endTime" type="hidden" />
    <div id="waitingdiv">
        @Html.Partial("~/Views/MonitorCenter/Loading.cshtml")
    </div>
    <div id="datadiv" style="height:560px;width:1100px;">
        <table id="datatable" class="easyui-datagrid"
                fitColumns="true"
                rownumbers="true"
                singleSelect="true"
                striped="true"
                loadMsg=""
                pagination="true"
                pageSize="20"
                fit="true">
            <thead>
                <tr>
                    <th field="mVehicleName">车牌号</th>
                    <th field="mDepart">所属单位</th>
                    <th field="mProjectName">项目名称</th>
                    <th field="mTime">日期</th>
                    <th field="mLeaveStationTime">出站时间</th>
                    <th field="mRetStationTime">返站时间</th>
                    <th field="mRemindTime" width="5000">提醒类型</th>
                </tr>
            </thead>
        </table>
    </div>
</div>
<script>
    $(document).ready(function () {
        InitPager($("#datatable"));
        GetData();
    });
    //初始化分页控件
    function InitPager(dg) {
        var pager = dg.datagrid('getPager');
        pager.pagination({
            pageSize: 20,//每页显示的记录条数，默认为10  
            beforePageText: '第',//页数文本框前显示的汉字  
            afterPageText: '页，共{pages}页',
            displayMsg: '当前显示{from}到{to}条记录，共{total}条记录',
            layout: ["first", "prev", "sep", "manual", "sep", "next", "last"]
        });
    }
    /*查询数据*/
    function GetData() {
        var startTime = $("#startTime").val();
        var endTime = $("#endTime").val();
        var vehicles = $(window.top.document).find("#vehicles").val();
        $("#waitingdiv").show();
        $.ajax({
            type: "post",
            url: "/IllegalWork/GetData",
            data: {
                "startTime": startTime,
                "endTime": endTime,
                "vehicles": vehicles
            },
            traditional: true,
            success: function (data) {
                if (data != "" && data != null && data.total != 0) {
                    $("#datatable").datagrid("loadData", { total: 0, rows: [] });
                    $('#datatable').datagrid({ loadFilter: pagerFilter }).datagrid('loadData', data);
                    $('#datatable').datagrid("getPager").pagination('select', 1);
                }
                else {
                    $("#datatable").datagrid("loadData", { total: 0, rows: [] });
                    historyData = null;
                }
                $("#waitingdiv").hide();
            },
            error: function (XMLHttpRequest) {
                $("#waitingdiv").hide();
                artDialogAlert("加载错误，错误代码：" + XMLHttpRequest.status);
            }
        });
    }
    /*本地分页*/
    function pagerFilter(data) {
        if (typeof data.length == 'number' && typeof data.splice == 'function') {    // is array
            data = {
                total: data.length,
                rows: data
            }
        }
        var dg = $(this);
        var opts = dg.datagrid('options');
        var pager = dg.datagrid('getPager');
        pager.pagination({
            pageSize: 20,//每页显示的记录条数，默认为10  
            beforePageText: '第',//页数文本框前显示的汉字  
            afterPageText: '页，共{pages}页',
            displayMsg: '当前显示{from}到{to}条记录，共{total}条记录',
            layout: ["first", "prev", "sep", "manual", "sep", "next", "last"],
            onSelectPage: function (pageNum, pageSize) {
                opts.pageNumber = pageNum;
                opts.pageSize = pageSize;
                pager.pagination('refresh', {
                    pageNumber: pageNum,
                    pageSize: pageSize
                });
                dg.datagrid('loadData', data);
            }
        });
        if (!data.originalRows) {
            data.originalRows = (data.rows);
        }
        var start = (opts.pageNumber - 1) * parseInt(opts.pageSize);
        var end = start + parseInt(opts.pageSize);
        data.rows = (data.originalRows.slice(start, end));
        return data;
    }
</script>